<tagLib name="lbase"/>
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>微信公众平台营销管理系统</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
    <include file='Public:header' />
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="__ROOT__/public/js/html5shiv.js"></script>
    <![endif]-->
</head>

<body>
    <!--nav-->
<include file='Public:nav' />

<div class="container">
    <!--            <ul class="breadcrumb">
                    <li><a href="#">首页</a> <span class="divider">/</span></li>
                    <li><a href="#">Library</a> <span class="divider">/</span></li>
                    <li class="active">Data</li>
                </ul>-->
    <div class="page-header"><h4>智能回复添加</h4></div>

    <!--<p class="view"><b>功能：</b>管理&nbsp;|&nbsp;添加|&nbsp;添加|&nbsp;添加|&nbsp;添加|&nbsp;添加</p>-->
    <div class="row">
        <div class="span12">
            <div class="pull-left">
                <a href="{:U('/'.$module_name)}" class="btn btn-primary">列 表</a>&nbsp;&nbsp;
                <!--<a href="{:U($module_name.'/add')}" class="btn btn-primary">新 增</a>&nbsp;&nbsp;-->
                <a class="btn btn-primary" href="{$pre_url}">返 回</a>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="span12" style="margin-top:10px;">
            <!--            <div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>登录成功！</div>-->

            <form class="form-horizontal" method="post">
                <fieldset>
                    <div id="legend" class="">
                        <legend class=""></legend>
                    </div>
                    <div class="control-group">
                        <!-- Select Basic -->
                        <label class="control-label">回复类型</label>
                        <div class="controls">
                            <select class="input-xlarge" name="msg_type">
                                <option value="1">单条文本</option>
                                <option value="2">单条图文</option>
                                <option value="3">图文列表</option>
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="input01">关键词</label>
                        <div class="controls">
                            <input type="text" name="keywords" placeholder="关键词" value="" class="input-xlarge">
                            <p class="help-block">请输入识别关键词，多个关键词请用空格或者逗号分隔</p>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="input01">标题</label>
                        <div class="controls">
                            <input type="text" name="title" placeholder="标题" value="" class="input-xlarge">
                            <p class="help-block">当为单条文本时，不在用户微信显示，只对管理员有标识作用</p>
                        </div>
                    </div>

                    <div class="control-group">
                        <!-- Textarea -->
                        <label class="control-label">描述</label>
                        <div class="controls">
                            <div class="textarea">
                                <textarea name="description"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <!-- Text input-->
                        <label class="control-label" for="input01">点击链接</label>
                        <div class="controls">
                            <input type="text" name="click_url" placeholder="点击的链接地址" class="input-xlarge">
                            <p class="help-block">完整的url链接，如为空，则自动生成文章内容页面</p>
                        </div>
                    </div>
                    <div class="control-group" id="pic_upload">
                        <label class="control-label">封面</label>

                        <!-- Button -->
                        <div class="controls">
                            <lbase:imgUpload name='imgupload' />
                            <p class="help-block">图片尺寸：640*320</p>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">状态</label>
                        <div class="controls">
                            <!-- Inline Radios -->
                            <label class="radio inline">
                                <input type="radio" value="1" name="status" checked="checked">
                                启用
                            </label>
                            <label class="radio inline">
                                <input type="radio" value="0" name="status">
                                禁用
                            </label>
                        </div>
                    </div><div class="control-group">

                        <!-- Textarea -->
                        <label class="control-label">内容</label>
                        <div class="controls">
                            <div class="textarea">
                                <lbase:editor name="contents" type="editor" width="70%" />
                                <p class="help-block">客户端显示的内容，当为单条文本时，请填写纯文本</p>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <!-- Text input-->
                        <label class="control-label" for="input01">优先级</label>
                        <div class="controls">
                            <input type="text" placeholder="排序" name="sort" value="9999" class="input-xlarge">
                            <p class="help-block">优先级数字越小，优先级越高。 如遇到单条文本优先级比图文高，则只会回复单条文本</p>
                        </div>
                    </div>

                    <div class="control-group">

                        <!-- Textarea -->
                        <label class="control-label">备注</label>
                        <div class="controls">
                            <div class="textarea">
                                <textarea name="remark"></textarea>
                            </div>
                        </div>
                        <div id='pop'></div>

                        <div class="form-actions">
                            <button type="button" class="btn btn-primary" id="save">保 存</button>&nbsp;&nbsp;
                            <a class="btn" href="{$pre_url}">返 回</a>
                        </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>
</div>
<include file='Public:footer' />
<script type="text/javascript">
                    $(function() {
                        $('[name=click_url]').parent().parent().hide();
                        $('#pic_upload').hide();
                        $('[name=msg_type]').change(function() {
                            msg_type_change()
                        });

                        function msg_type_change() {
                            var value = $('[name=msg_type]').val();

                            switch (value) {
                                case "1":
                                    $('[name=click_url]').parent().parent().hide();
                                    $('#pic_upload').hide();
                                    break;
                                case "2":
                                    $('[name=click_url]').parent().parent().show();
                                    $('#pic_upload').show();
                                    break;
                                case "3":
                                    $('[name=click_url]').parent().parent().show();
                                    $('#pic_upload').show();
                                    break;
                            }
                        }

                        $('#save').click(function() {
                            contents_editor.sync();
                            var data = $('form').serialize();
                            $('#save').attr('disabled', 'disabled');
                            $.ajax({
                                type: "POST",
                                url: app_url + "/" + module_name + "/insert",
                                data: data,
                                dataType: 'json',
                                cache: false,
                                success: function(data) {
                                    success(data);
                                },
                                error: function() {
                                    error();
                                }
                            });


                        });

                        $('#pop').ajaxStart(function() {
                            $('#pop').html('<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>数据请求中，请稍候...</div>')
                                    .fadeIn("slow");
                        });

                        function success(data) {
                            if (data.data == 1) {
                                $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>信息添加成功！</div>')
                                        .fadeIn("slow")
                                        .fadeOut(5000);
                            } else {
                                $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>信息添加失败！</div>')
                                        .fadeIn("slow")
                                        .fadeOut(5000);
                            }
                        }


                        function error() {
                            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>远程服务器请求失败！</div>')
                                    .fadeIn("slow")
                                    .fadeOut(5000);
                        }
                    });
</script>
</body>
</html>
